home *** CD-ROM | disk | FTP | other *** search
- Path: hickory.westol.com!news
- From: Mark Kintigh <breetai@oak.westol.com>
- Newsgroups: comp.lang.c
- Subject: Re: Converting Strings to Upper Case
- Date: Mon, 18 Mar 1996 08:17:20 -0800
- Organization: Westmoreland Online Inc.
- Message-ID: <314D8C90.55C6@oak.westol.com>
- References: <4ifra6$52i@scipio.cyberstore.ca> <4ih7l3$526@thrush.sover.net>
- NNTP-Posting-Host: pm126.westol.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win16; I)
-
- Steve Mount wrote:
- >
- > In article <4ifra6$52i@scipio.cyberstore.ca>, ejw@news.cyberstore.ca says...
- > >I need to write a function to convert a string containg upper or lower case
- > >characters to the opposite case. Something like::
- > void strnlwr(char *buffer, int len)
- > {
- > register int i;
- > for (i=0;i<len;i++) buffer[i] = tolower(buffer[i]);
- > return;
- > }
- >
- > Note I added a length checker, as this was required; it may not be the most
- > efficient, but it gets the job done. It also prevents me from duplicating
- > the code that tolower/toupper does.
-
- You don't need the length. You could just use....
-
- void str2upper(char *str)
- {
- while(*str!='\0')
- {
- *str = toupper(*str);
- str++;
- }
- }
-
- Of course, this assumes that you have properly terminated the string. :)
- --
- _____
- / /## breetai@oak.westol.com
- / /#### ____
- (| []/ o ##) "We met the enemy, and they were'nt us, then | _|||
- |\ \_/ /\ # /| we faced a pannel of 'us' and found they were || ||
- | \-\ ==== /-/ | the enemy." \\//
- ||\\ '----' //|| \/
- || \\/ \// ||
-